<?php
	include_once('../sys/sys.php');
	include_once('./gfun.php');
	include_once('./funcs.php');
	header('Content-Type: text/html; charset=utf-8');
	
	$tid = $_GET['tid'];
	
	if(!is_numeric($tid) || $tid < 0){
		show_normal_mesR('TAG ID错误','TAG ID错误','TAG查询');
	}
	
	
	
	//分离URL以及ID
	$id = $tid;
	//定义公用变量
	$url = $gfun_cat_urlpre . $tid;
	//获取URL内容
	//$url = 'E:\web\hf\gfun\test\fenlei.html';
	$content = 	file_get_contents($url);
	//获取总页数
	$total_pages = explode('" title="末页"',$content);
	$total_pages = $total_pages[0];
	$total_pages = explode('下一页</a></li><li class="next">',$total_pages);
	$total_pages = $total_pages[1];
	$total_pages = explode('DownNum&CurrPage=',$total_pages);
	$total_pages = $total_pages[1];
	$total_pages = explode('&',$total_pages);
	$total_pages = $total_pages[0];
// 	echo $total_pages;exit;
	unset($content);
	
	//获取应用列表(每页进行)
	for ($i = 1;$i <= $total_pages; $i++){
		$current_cat_pg_url = $gfun_cat_urlpre . $tid . '&orderBy=UpdateTime&CurrPage=' . $i;
		$content = 	file_get_contents($current_cat_pg_url);
		$cp_ids = get_page_apps($tid,$content,$DB);
		//更新单个应用信息
		foreach ($cp_ids as $v) {
			get_single_app($DB,$gfun_app_pre,$v);
		}
		echo '第<B><font color="red">'  . $i . "</font></B>页采集完毕<BR>";
		ob_flush();
	}
	
	echo "分类采集完毕";
	ob_end_flush();
	
	
	exit;
	
	
?>